﻿using System;
using nRoute.Components.Composition;
using nRoute.Components.Routing;
using nRoute.Controllers.Mapping;
using nRoute.Utilities;

namespace nRoute.Mapping
{
    public class DefaultControllerLocator
        : ResourceLocatorBase
    {
        private readonly Object _lock = new Object();
        private readonly string _url;
        private readonly Type _controllerType;
        
        public DefaultControllerLocator(string url, Type controllerType)
        {
            Guard.ArgumentNotNullOrWhiteSpace(url, "url");
            Guard.ArgumentNotNull(controllerType, "controllerType");

            _url = url;
            _controllerType = controllerType;
        }

#region Properties

        public string Url
        {
            get { return _url; }
        }

        public Type ControllerType
        {
            get { return _controllerType; }
        }

#endregion

#region Override

        protected override object GetInstance(ITypeBuilder typeBuilder)
        {
            return new ControllerHandler(typeBuilder, this.ControllerType);
		}

#endregion

    }
}
